﻿/// <summary>
/// 数据库注入
/// </summary>
public static class SqlSugarInit
{
    /// <summary>
    /// 注入数据库
    /// </summary>
    /// <param name="services"></param>
    public static void AddSqlsugarSetup(this IServiceCollection services)
    {
        //如果多个数数据库传 List<ConnectionConfig>
        var configConnection = new ConnectionConfig()
        {
            DbType = SqlSugar.DbType.MySql,

            ConnectionString = App.Configuration.GetSection("connStr").Value,

            IsAutoCloseConnection = true,

            ConfigureExternalServices = new ConfigureExternalServices
            {
              DataInfoCacheService = new DbCache()
            }
        };


        SqlSugarScope sqlSugar = new SqlSugarScope(configConnection,

            db =>
            {
                //单例参数配置，所有上下文生效
                db.Aop.OnLogExecuting = (sql, pars) =>
                {
                   
                };
            });


        services.AddSingleton<ISqlSugarClient>(sqlSugar);
    }
}

